import React, { Component } from 'react'



export default class Count extends Component {
    state = {
        isHot: true,
    }

    render() {
        console.log('UI组件的props', this.props);
        const { sum } = this.props;
        return (
            <div>
                <h1>今天天气{this.state.isHot ? "炎热" : "寒冷"}</h1>
                <h2>当前的值是{sum}</h2>
                <div>
                    <select ref={c => this.selectEle = c}>
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                    </select>
                    <button onClick={this.increment}>+</button>
                    <button onClick={this.decrement}>-</button>
                    <button onClick={this.incrementOdd}>如果奇数再加</button>
                    <button onClick={this.incrementWait}>延迟1s再加</button>
                </div >
            </div >
        )
    }
    increment = () => {
        const { value } = this.selectEle;
        const { jia } = this.props;
        jia(+value);

    }
    decrement = () => {
        const { value } = this.selectEle;
        const { jian } = this.props;
        jian(+value);

    }
    incrementOdd = () => {
        const { value } = this.selectEle;
        const { jia, sum } = this.props;
        if (sum % 2 === 0) return alert('偶数不加');
        jia(+value);


    }
    incrementWait = () => {
        const { value } = this.selectEle;
        const { dydjia } = this.props;
        dydjia(+value);

    }
}
